
capture log close
log using $log/EDS_14_graph_main_results", text replace

clear
clear matrix
clear mata
set mem 2g
set matsize 800
set more off
set maxvar 20000
set trace off
set varabbrev off



		#d;
		  global cov "  _Isu_schule_1 _Isu_schule_2 _Isu_schule_3 
	_Isu_ausbila1 _Isu_ausbila2
	_Isu_kat_al_2 _Isu_kat_al_3 _Isu_kat_al_4 
	_Ichild_1 _Ichild_2
	_Isu_eintri_1 _Isu_eintri_2 _Isu_eintri_3 _Isu_eintri_4 _Isu_eintri_5
	_Isu_eintri_6 _Isu_eintri_7 _Isu_eintri_8 _Isu_eintri_9 _Isu_eintri_10 _Isu_eintri_11
	_Ibefstat_1 _Ibefstat_2 _Ibefstat_3 _Ibefstat_4
	_Idauloint__8 _Idauloint__9 _Idauloint__10 _Idauloint__11 _Idauloint__12 
	_Idauloint__13 _Idauloint__14
	female east_germany
    german migration_background 
    married  
	benefit_status benefit_level log_benefit_level
    lifetime_ue_age lifetime_empl_age last_wage last_wage_mis 
    region_ba_aloq_zivall gdp_real_pc region_ba_vacancies 
	sector_manufacturing sector_service  log_mobirate_avg5
	openness_st conscient_st extraversion_st neuroticism_st loc_st
	write_ger speak_ger write_eng speak_eng
	homeowner  
	   ";		
		
		#d cr

		use $data/data_pair,clear



		qui reg log_intensity_alt  $cov county_pair_* [pw=1/fweight_reg] , cluster(region)
	    predict pred_int,xb
		gen res_int=log_intensity_alt-pred_int
		
		
		qui sum res_int,d
		drop if res_int>r(p99)|res_int<r(p1)
		
		
		foreach var in search_dist50 {
		local name "prob. to apply for distant vacancy"
		
		qui reg `var' $cov county_pair_* [pw=1/fweight_reg] , cluster(region)
	    predict pred_`var',xb
		gen res_`var'=`var'-pred_`var'
	
		
		#d;
		twoway (hist res_int, frac yaxis(1))
		(lpolyci res_`var' res_int, fintensity(inten20) level(90) yaxis(2) 
		ytitle("Residual variation in `name'", axis(2))
		yline(0, lpattern(dash) axis(2))),
		scheme(s2mono) graphregion(color(white)) legend(off) 
		xtitle("Residual variation in log treatment intensity");
		#d cr
		graph export $data/Figure_2_survey.png, as(png) replace
		
		}		
		
		
		
		
	
	 
	  
	
	   	
log close	

